package com.lenovo.vod.player.callback;

import com.lenovo.vod.player.Constant;
import com.lenovo.vod.player.Engine;

import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.util.Log;

public class BufferingUpdateListener implements OnBufferingUpdateListener {
	private Engine mEngine;

	public BufferingUpdateListener(Engine engine) {
		mEngine = engine;
	}

	@Override
	public void onBufferingUpdate(MediaPlayer arg0, int percent) {
		if (!mEngine.getBufferCompleted())
			mEngine.showBuffer(percent);

		if (!mEngine.getBufferStarted() && percent < 100) {
			Log.d(Constant.TAG,
					"onBufferingUpdate called. Start buffering[percent: "
							+ percent + "%]");
			mEngine.setBufferStarted(true);
		}

		if (mEngine.getBufferStarted() && !mEngine.getBufferCompleted()) {

			if (percent == 100) {
				Log.d(Constant.TAG,
						"onBufferingUpdate called. End buffering[percent: "
								+ percent + "%]");

				mEngine.setBufferCompleted(true);
				mEngine.hideBuffer();
			}
		}

//		if (mEngine.getBufferStarted()) {
//			mEngine.setSecondaryProgress(percent);
//		}
	}
}
